<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    // reduce 方法,数组的求和方法
    let arr = [2, 3, 4, 5, 6]
    // 语法一: 
    // let res = arr.reduce((总和, 数组元素) => {
    //   return 累加的式子
    // }, 初始值)
    let res1 = arr.reduce((t, item) => {
      return t + item
    }, 100)
    console.log(res1);
    // 语法二:
    // let res2 = arr.reduce((总和, 数组元素) => {
    //   return 累加的式子
    // })
    let res2 = arr.reduce((t, item) => {
      return t + item
    })
    console.log(res2);

    // 实例
    let list = [
      { id: 21, subject: '语文', score: 90 },
      { id: 31, subject: '语文', score: 100 },
      { id: 41, subject: '语文', score: 80 },
    ]
    let res = list.reduce((t, c) => {
      return t + c.score
    }, 0)
    console.log(res);
  </script>
</body>

</html>